package observer;

import state.Globals;
import state.group.events.DirectionEvent;
import state.group.events.DoorEvent;
import state.group.events.ElevatorEvent;
import state.group.events.FloorEvent;

/**
 * 
 * This class is meant to hold the important information 
 * in order
 * 
 * @author Ian Doerr
 *
 */
public class ElevatorPartialStruct {
    
    private byte identifier;
    
    private byte doorOpen;
    private byte lastKnownFloor;
    private byte direction;
    
    public synchronized void updateStruct(ElevatorEvent event)
    {
        
        if (event.getElevatorId() != identifier)
        {
            return;
        }
        
        switch (event.getEventType())
        {
            case DirectionEvent:
                this.direction = ((DirectionEvent) event).getDirection();
                break;
            case DoorEvent:
                this.doorOpen = ((DoorEvent) event).isOpen();
                break;
            case FloorEvent:
                this.lastKnownFloor = ((FloorEvent) event).getFloor();
                Globals.getLogger().log("Floor : " + lastKnownFloor);
                break;
            case RegistrationEvent:
                //NOOP
            	break;
            case DeregistrationEvent:
                //NOOP
            	break;
            case StartEvent:
                //NOOP
            	break;
            case StopEvent:
                //NOOP
            	break;
        }
        
    }

    
    
	public synchronized void setIdentifier(byte identifier) {
		this.identifier = identifier;
	}

	public synchronized void setDoorOpen(byte doorOpen) {
		this.doorOpen = doorOpen;
	}

	public synchronized void setLastKnownFloor(byte lastKnownFloor) {
		this.lastKnownFloor = lastKnownFloor;
	}

	public synchronized void setDirection(byte direction) {
		this.direction = direction;
	}

	public synchronized byte getIdentifier() {
		return identifier;
	}

	public synchronized byte getDoorOpen() {
		return doorOpen;
	}

	public synchronized byte getLastKnownFloor() {
		return lastKnownFloor;
	}

	public synchronized byte getDirection() {
		return direction;
	}
    
    
}
